#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 微信授权绑定功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

from examples.base_example import BaseExample
from jlpay.services.trans.mini.wx.auth_bind_service import AuthBindService
from jlpay.model.trans.mini.wx.auth_bind import (
    AuthBindRequest, AuthBindResponse
)


class AuthBindExample(BaseExample):
    """微信授权绑定示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.mini.wx.auth_bind")
        self.service = AuthBindService(self.config)
    
    def build_auth_bind_request(self):
        """
        构建微信授权绑定请求
        
        Returns:
            AuthBindRequest实例
        """
        request = AuthBindRequest()
        request.set_mch_id("849584358120018")
        request.set_pay_type("wxpay")
        request.set_jsapi_path("http://wx.com/jspay/pay/")
        request.set_sub_appid("wx1234567890abcdef")
        request.set_mch_create_ip("127.0.0.1")
        return request
    
    def demo(self):
        """执行微信授权绑定示例"""
        self.logger.info("开始执行微信授权绑定示例")
        
        # 构建请求
        request = self.build_auth_bind_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.service.auth_bind,
            "微信授权绑定",
            request
        )
        
        self.logger.info("微信授权绑定示例执行完毕")


if __name__ == "__main__":
    logger = AuthBindExample().logger
    logger.info("==================================================")
    logger.info("===== 微信授权绑定示例 开始 =====")
    logger.info("==================================================")
    
    example = AuthBindExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 微信授权绑定示例执行完毕 =====")
    logger.info("==================================================") 